package cn.doit.day04

import java.io
import scala.collection.mutable
import scala.collection.parallel.immutable

object _05_元祖 {
  def main(args: Array[String]): Unit = {
    //元祖的创建，总共有三种方式
    val tuple: (Int, String, Boolean) = Tuple3(1, "zss", true)
    val tuple1: (Int, String, String, Boolean) = new Tuple4[Int, String, String, Boolean](1, "zss", "lss", true)

    //优先选择第三种创建方式
    val tuple2: (Int, String, Int, String) = (1, "zss", 18, "male")
    //不去创建scalaBean类，
    val tuple3: (Int, String, String) = (1, "liuyan", "female")

    //获取元素
    println(tuple3._1)//1
    println(tuple3._2)//liuyan
    println(tuple3._3)//female

    //二元元祖 =》 对偶元祖 (key,value)
    val tuple4: (Int, String) = Tuple2(1, "zss")

    //map  HashMap  可变的
    val map: mutable.Map[Int, String] = mutable.Map()


    //不可变的map
    val map1: Map[Int, String] = Map[Int,String]()

    //定义了一个不可变的map
    val map2: Map[Int, String] = Map(1 -> "zss", 2 -> "lss", 3 -> "ww")

    for (elem <- map2) {
      val key: Int = elem._1
      val value: String = elem._2
    }

    //对偶元祖
    val map4: Map[Int, String] = Map((1, "zss"), (2, "lss"), (3, "ww"), (4, "liuyan"))

    //只有这一种情况可以将list转变成map
/*
    val list: List[(Int, String)] = List((2, "zss"), (2, "lss"), (3, "ww"), (4, "liuyan"))

    val map3: Map[Int, String] = list.toMap
    for (elem <- map3) {
      println(elem)
    }
*/

    //防呆
    val maybeString: Option[String] = map4.get(5)//some  none
      val value: String = maybeString.get


    val str: String = map4.getOrElse(1, "abc")
    println(str)
    val res: String = map4.getOrElse(5, "abc")
    println(res)



  }
}
